package com.pearadmin.pro.common.configure;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;

/**
 * Swagger 文档配置
 *
 * Author: 就 眠 仪 式
 * CreateTime: 2021/04/01
 * */
@Configuration
@EnableSwagger2
public class SwaggerConfig  {

    private static final String BASE_PACKAGE = "com.pearadmin";

    private static final String DEFAULT_GROUP = "default";

    private static final Boolean ENABLE = true;

    @Bean
    public Docket docker(){
        List<Parameter> pars = new ArrayList<>();
        ParameterBuilder tokenPar = new ParameterBuilder();
        tokenPar.name("Authorization").description("令牌").modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build();
        pars.add(tokenPar.build());
        tokenPar.name("Authorization-key").description("令牌key").modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build();
        pars.add(tokenPar.build());
//        return new Docket(DocumentationType.SWAGGER_2).enable(true)
//                .apiInfo(apiInfo()).globalOperationParameters(pars);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .globalOperationParameters(pars)
                .groupName(DEFAULT_GROUP)
                .enable(ENABLE)
                .select()
                .apis(RequestHandlerSelectors.basePackage(BASE_PACKAGE))
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfo(
                "课联 SCR API",
                "课联 SCRM" ,
                "",
                "课联 SCR",new Contact("课联 SCR","课联 SCR","课联 SCR"),
                "apache license",
                "课联 SCR",
                new ArrayList<>()
        );
    }

}
